//
//  ThirdPerson_Government.m
//  HappyStore
//
//  Created by 点点充 on 16/1/29.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "ThirdPerson_Government.h"

@interface ThirdPerson_Government ()
{
    NSMutableDictionary *dicData;
    
    NSInteger seleType;//选择的哪个类型
    
    
    NSArray *aryTitle1;
    NSMutableArray *muAryTitleContent;
    
    UIImage *imgUserHeaderImg;//用户头像
    UIButton *btnHeader;
    UIButton *btnUserName;//用户名称
    
    UIView *_slideView;
    
    BOOL isFirstAddSlide;
    
    NSInteger paggge;
    
    NSMutableArray *muAryData;
    
    UIButton *btnLove;
    
    NSArray *TopPhotos;
    NSArray *muAryLeadership;
}
@end

@implementation ThirdPerson_Government

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = self.strUserName;
    
    self.btnPhone.layer.masksToBounds = YES;
    self.btnPhone.layer.cornerRadius = 5.f;
    
    self.btnMessage.layer.masksToBounds = YES;
    self.btnMessage.layer.cornerRadius = 5.f;
    
    seleType = 0;//概况
    
    [self startPostNetWorkInfo];
    
    _mainTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        paggge += 1;
        [self startSearch];
    }];
    _mainTableView.mj_footer.hidden = YES;
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}


#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (seleType == 0) {
        return 5;
    }
    else if(seleType <3) {
        
        return muAryData.count+1;
    }
    else {
        return 2;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 220;
    }
    else {
        if (seleType == 0) {
            if (indexPath.row < aryTitle1.count+1) {//个人信息
                return 44;
            }else if (indexPath.row == aryTitle1.count+1) {//企业简介
                CGSize size1 = CGSizeMake(0, 0);
                if (dicData[@"cicasetxt"] == [NSNull null] || [dicData[@"cicasetxt"] isEqualToString:@"null"]) {
                    
                    return 208+158*TopPhotos.count+8;
                }else {
                    size1 = [LLJLabelHeight UIlabelGetFont:16.f sizeWidth:300 strNeirong:dicData[@"cicasetxt"]];
                    return size1.height+208+158*TopPhotos.count+8;
                }
            }else {
                return 44;
            }
        }else if(seleType <3) {//项目
            return 110;
        }else {//政策
            NSString *strText;
            switch (seleType) {
                case 3://政策
                {
                    strText = dicData[@"policytxt"];
                }
                    break;
                case 4://产业规划
                {
                    strText = dicData[@"industryplanningtxt"];
                }
                    break;
                case 5://区域
                {
                    strText = dicData[@"areatxt"];
                }
                    break;
                default:
                    return 44;
                    break;
            }
            
            if (strText.length == 0 || [strText isEqualToString:@"null"]) {
                return 8+158*TopPhotos.count+8;
            }else {
                CGSize size1 = [LLJLabelHeight UIlabelGetFont:16.f sizeWidth:300 strNeirong:strText];
                return size1.height+8+158*TopPhotos.count+8;
            }
        }
    }
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellHeader = @"cellHeader";//头像
    static NSString *cellSex = @"cellSex";//信息
    static NSString *celllingdao = @"celllingdao";//领导
    
    static NSString *cellZhengce = @"cellZhengce";//政策
    
    static NSString *cell2 = @"cell2";//项目
    
    
    UITableViewCell *cell;
    
    if (indexPath.row == 0) {
        cell = [tableView dequeueReusableCellWithIdentifier:cellHeader forIndexPath:indexPath];
        //头像
        btnHeader = [cell viewWithTag:10];
        btnHeader.layer.masksToBounds = YES;
        btnHeader.layer.cornerRadius = 35;
        [btnHeader setImage:nil forState:UIControlStateNormal];
        [btnHeader sd_setBackgroundImageWithURL:[NSURL URLWithString:dicData[@"headPhoto"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"btn_my_touxiang"]];
//        [btnHeader sd_setImageWithURL:[NSURL URLWithString:dicData[@"headPhoto"]] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"btn_my_touxiang"]];
        
        UIImageView *imgVip = [cell viewWithTag:11];
        if ([dicData[@"vipLevel"] integerValue] == 0) {
            imgVip.image = [UIImage imageNamed:@"img_my_vip2"];
        }else {
            imgVip.image = [UIImage imageNamed:@"img_my_vip1"];
        }
        //名称
        btnUserName = [cell viewWithTag:12];
        if (dicData[@"username"] == [NSNull null] || [dicData[@"username"] isEqualToString:@"null"]) {
            [btnUserName setTitle:dicData[@"account"] forState:UIControlStateNormal];
        }else {
            [btnUserName setTitle:dicData[@"username"] forState:UIControlStateNormal];
        }
        
        if (!isFirstAddSlide) {
            _topScrollView = [[UIScrollView alloc] initWithFrame:(CGRect){0,166,320,50}];
            [cell addSubview:_topScrollView];
            [self addTopButton];
            isFirstAddSlide = YES;
        }
        
        //粉丝
        btnLove = [cell viewWithTag:20];
        btnLove.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6f];
        btnLove.layer.masksToBounds = YES;
        btnLove.layer.cornerRadius = 8.0f;
        [btnLove setTitle:[NSString stringWithFormat:@"%@",dicData[@"focusNumber"]] forState:UIControlStateNormal];
        if ([dicData[@"isFocus"] isEqualToString:@"否"]) {
            [btnLove setImage:[UIImage imageNamed:@"project_detail_taoxin_normal"] forState:UIControlStateNormal];
        }else {
            [btnLove setImage:[UIImage imageNamed:@"project_detail_taoxin_pressed"] forState:UIControlStateNormal];
        }
        [btnLove addTarget:self action:@selector(btnClickLove) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    else {
        
        if (seleType == 0) {
            if (indexPath.row <aryTitle1.count+1) {//个人信息
                cell = [tableView dequeueReusableCellWithIdentifier:cellSex forIndexPath:indexPath];
                
                UILabel *labTitle = [cell viewWithTag:10];
                labTitle.text = aryTitle1[indexPath.row-1];
                
                UILabel *labContent = [cell viewWithTag:11];
                labContent.text = muAryTitleContent[indexPath.row-1];
                
            }else {
                //政府概括
                cell = [tableView dequeueReusableCellWithIdentifier:celllingdao forIndexPath:indexPath];
                for (int i = 0; i<4; i++) {
                    UIButton *btnadd = [cell viewWithTag:20+i];
//                    [btnadd addTarget:self action:@selector(btnClickAddLingdaoImag:) forControlEvents:UIControlEventTouchUpInside];
                    
                    UILabel *labPosition = [cell viewWithTag:30+i];
                    UILabel *labName = [cell viewWithTag:40+i];
                    if (i<muAryLeadership.count) {
                        btnadd.userInteractionEnabled = NO;
                        [btnadd sd_setImageWithURL:[NSURL URLWithString:muAryLeadership[i][@"leaderHead"]] forState:UIControlStateNormal];
                        labPosition.text = muAryLeadership[i][@"leaderPosition"];
                        labName.text = muAryLeadership[i][@"leaderName"];
                    }else {
                        btnadd.userInteractionEnabled = YES;
                        [btnadd setImage:nil forState:UIControlStateNormal];
                        labPosition.text = @"";
                        labName.text = @"";
                    }
                }
                
                
                
                CGSize size1 = CGSizeMake(0, 208);
                if (dicData[@"cicasetxt"] == [NSNull null] || [dicData[@"cicasetxt"] isEqualToString:@"null"]) {
                    for (int i = 0; i<TopPhotos.count; i++) {
                        UIImageView *img = [[UIImageView alloc] initWithFrame:(CGRect){10,(size1.height)+158*i,300,150}];
                        [img sd_setImageWithURL:[NSURL URLWithString:TopPhotos[i]] placeholderImage:[UIImage imageNamed:@"img_normal1"]];
                        [cell addSubview:img];
                    }
                    
                }else {
                    UILabel *labContent = [[UILabel alloc] init];
                    size1 = [LLJLabelHeight UIlabelGetFont:16.f sizeWidth:300 strNeirong:dicData[@"cicasetxt"]];
                    labContent.frame = (CGRect){10,208,300,size1.height};
                    labContent.text = dicData[@"cicasetxt"];
                    labContent.font = [UIFont systemFontOfSize:16.f];
                    labContent.textColor = [UIColor colorWithRed:89/255.0f green:87/255.0f blue:87/255.0f alpha:1.0f];
                    labContent.numberOfLines = 0;
                    [cell addSubview:labContent];
                    
                    for (int i = 0; i<TopPhotos.count; i++) {
                        UIImageView *img = [[UIImageView alloc] initWithFrame:(CGRect){10,(labContent.frame.origin.y + labContent.frame.size.height + 8)+158*i,300,150}];
                        [img sd_setImageWithURL:[NSURL URLWithString:TopPhotos[i]] placeholderImage:[UIImage imageNamed:@"img_normal1"]];
                        [cell addSubview:img];
                    }
                    
                }
            }
            
        }
        else if (seleType < 3 ){//项目、活动
            BOOL nibsRegistered3 = NO;
            if (!nibsRegistered3) {
                UINib *nib=[UINib nibWithNibName:@"TableViewCell2" bundle:nil];
                [tableView registerNib:nib forCellReuseIdentifier:cell2];
                nibsRegistered3=YES;
            }
            
            NSLog(@"%ld",indexPath.row);
            cell = [tableView dequeueReusableCellWithIdentifier:cell2];
            
            UIButton *btn = [cell viewWithTag:10];//lable
            btn.userInteractionEnabled = NO;
            if (muAryData[indexPath.row-1][@"lable"] == [NSNull null] || [muAryData[indexPath.row-1][@"lable"] isEqualToString:@"null"]) {
                btn.hidden = YES;
            }else {
                NSString *_string = muAryData[indexPath.row-1][@"lable"];
                NSArray *_arr = [_string componentsSeparatedByString:NSLocalizedString(@",", nil)];
                [btn setTitle:_arr[0] forState:UIControlStateNormal];
            }
            
            
            UIImageView *imgV = [cell viewWithTag:20];
            [imgV sd_setImageWithURL:[NSURL URLWithString:muAryData[indexPath.row-1][@"logo"]] placeholderImage:[UIImage imageNamed:@"img_normal3"]];
            imgV.layer.masksToBounds = YES;
            imgV.layer.cornerRadius = 5.f;
            
            UILabel *labTitle = [cell viewWithTag:21];
            labTitle.text = muAryData[indexPath.row-1][@"title"];
            
            UILabel *labPrice = [cell viewWithTag:22];
            labPrice.text = [CustomExcetion comperNumber:muAryData[indexPath.row-1][@"investment"]];
            
            UILabel *labAddress = [cell viewWithTag:23];
            labAddress.text = muAryData[indexPath.row-1][@"address"];
            
            UILabel *labPeople = [cell viewWithTag:24];
            if (muAryData[indexPath.row-1][@"username"] == [NSNull null] || [muAryData[indexPath.row-1][@"username"] isEqualToString:@"null"]) {
                labPeople.text = muAryData[indexPath.row-1][@"account"];
            }else {
                labPeople.text = muAryData[indexPath.row-1][@"username"];
            }
            
            
            UILabel *labDate = [cell viewWithTag:25];
            NSDate *date = [CustomExcetion dateFromString:muAryData[indexPath.row-1][@"createtime"]];
            labDate.text = [CustomExcetion prettyDateWithReference:date];
        }
        else {//政策、规划、区域
            cell = [tableView dequeueReusableCellWithIdentifier:cellZhengce forIndexPath:indexPath];
            
            for (UIView *view in cell.subviews) {
                if ([view isKindOfClass:[UILabel class]]) {
                    [view removeFromSuperview];
                }
                if ([view isKindOfClass:[UIImageView class]]) {
                    [view removeFromSuperview];
                }
            }
            
            NSString *strText;
            switch (seleType) {
                case 3://政策
                {
                    strText = dicData[@"policytxt"];
                }
                    break;
                case 4://产业规划
                {
                    strText = dicData[@"industryplanningtxt"];
                }
                    break;
                case 5://区域
                {
                    strText = dicData[@"areatxt"];
                }
                    break;
            }
            
            
            CGSize size1 = CGSizeMake(0, 8);
            if (strText.length == 0 || [strText isEqualToString:@"null"]) {
                for (int i = 0; i<TopPhotos.count; i++) {
                    UIImageView *img = [[UIImageView alloc] initWithFrame:(CGRect){10,(size1.height)+158*i,300,150}];
                    [img sd_setImageWithURL:[NSURL URLWithString:TopPhotos[i]] placeholderImage:[UIImage imageNamed:@"img_normal1"]];
                    [cell addSubview:img];
                }
                
            }else {
                UILabel *labContent = [[UILabel alloc] init];
                size1 = [LLJLabelHeight UIlabelGetFont:16.f sizeWidth:300 strNeirong:strText];
                labContent.frame = (CGRect){10,8,300,size1.height};
                labContent.text = strText;
                labContent.font = [UIFont systemFontOfSize:16.f];
                labContent.textColor = [UIColor colorWithRed:89/255.0f green:87/255.0f blue:87/255.0f alpha:1.0f];
                labContent.numberOfLines = 0;
                [cell addSubview:labContent];
                
                for (int i = 0; i<TopPhotos.count; i++) {
                    UIImageView *img = [[UIImageView alloc] initWithFrame:(CGRect){10,(labContent.frame.origin.y + labContent.frame.size.height + 8)+158*i,300,150}];
                    [img sd_setImageWithURL:[NSURL URLWithString:TopPhotos[i]] placeholderImage:[UIImage imageNamed:@"img_normal1"]];
                    [cell addSubview:img];
                }
                
            }
            
            
            
        }
        
        
    }
    
    
    return cell;
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];//取消选中状态
    
    //取消显示后退键文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    
    switch (seleType) {
        case 1://项目
        {
            Project_Detail *project_detail = [self.storyboard instantiateViewControllerWithIdentifier:@"project_detail"];
            project_detail.projectId = muAryData[indexPath.row-1][@"projectId"];
            [self.navigationController pushViewController:project_detail animated:YES];
        }
            break;
        case 2://活动
        {
            BusinessActivity_Detail *business_Detail = [self.storyboard instantiateViewControllerWithIdentifier:@"business_detail"];
            business_Detail.activityId = muAryData[indexPath.row-1][@"activityId"];
            [self.navigationController pushViewController:business_Detail animated:YES];
        }
            break;
    }
    
    
}


#pragma mark - 基本信息
- (void)startPostNetWorkInfo
{
    [self showRoundProgressWithTitle:@"请稍后..."];
    
    //token=rE3F2m8AvfC7CVh85O9q&userId=9&userType=用户类型 1-个人，2-企业，3-政府
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    [muDicParameters setObject:self.strUserType forKey:@"userType"];//用户类型 1-个人，2-企业，3-政府
    [muDicParameters setObject:self.strUserId forKey:@"userId"];
//    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    if ([USER_DEFAULTS objectForKey:@"userid"] != nil) {
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"MyUserId"];
    }
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"MyBasicMessage_app_myHome.im"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//        NSLog(@"%@",dicInfo);

        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            dicData = [NSMutableDictionary dictionaryWithDictionary:dicInfo[@"data"]];
            
            NSMutableString *muStr = [NSMutableString string];
            BOOL isNull = NO;
            if (dicData[@"companyAccount"] == [NSNull null] || [dicData[@"companyAccount"] isEqualToString:@"null"]) {
                if (dicData[@"companyUserName"] == [NSNull null] || [dicData[@"companyUserName"] isEqualToString:@"null"] ) {
                    isNull = YES;
                }
                
            }else {
                if (dicData[@"companyUserName"] == [NSNull null] || [dicData[@"companyUserName"] isEqualToString:@"null"]) {
                    [muStr appendFormat:@"%@",dicData[@"companyAccount"]];
                }else {
                    [muStr appendFormat:@"%@",dicData[@"companyUserName"]];
                }
                
            }
            
            if (dicData[@"goveAccount"] == [NSNull null] || [dicData[@"goveAccount"] isEqualToString:@"null"]) {
                if (dicData[@"goveUserName"] == [NSNull null] || [dicData[@"goveUserName"] isEqualToString:@"null"]) {
                    if (isNull) {
                        [muStr appendString:@"无"];
                    }
                    
                }
            }else {
                if (dicData[@"goveUserName"] == [NSNull null] || [dicData[@"goveUserName"] isEqualToString:@"null"]) {
                    [muStr appendFormat:@"%@",dicData[@"goveAccount"]];
                }else {
                    [muStr appendFormat:@"%@",dicData[@"goveUserName"]];
                }
                
            }
            
            
            aryTitle1 = @[@"隶属组织:",@"联系方式:",@"所在地区:"];
            muAryTitleContent = [NSMutableArray arrayWithObjects:muStr,dicData[@"mobile"],dicData[@"address"], nil];
            
            TopPhotos = dicData[@"cicasephoto"];
            
            muAryLeadership = [NSArray arrayWithArray:dicData[@"leadership"]];
            
            
            [self hideBubble];
            
            [_mainTableView reloadData];

        }else {

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];

        }
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
}



- (void)addTopButton
{
    NSArray *aryItem = @[@"概况",@"项目",@"活动",
                         @"政策",@"产业规划",@"区域位置"];
    CGFloat width = 77;
    _topScrollView.showsHorizontalScrollIndicator = NO;
    _topScrollView.showsVerticalScrollIndicator = YES;
    _topScrollView.contentSize = CGSizeMake(78 * 6, 50);
    
    for (int i = 0; i < aryItem.count; i ++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i * width, 0, width, 48)];
        button.tag = i;
        [button setTitle:aryItem[i] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(tabButton:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitleColor:[UIColor colorWithRed:89/255.f green:87/255.f blue:87/255.f alpha:1.f] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:15.f];
        [_topScrollView addSubview:button];
        
        UILabel *labH = [[UILabel alloc] initWithFrame:(CGRect){i*width+78,10,1,30}];
        labH.backgroundColor = [UIColor colorWithRed:170/255.f green:170/255.f blue:170/255.f alpha:1.f];
        [_topScrollView addSubview:labH];
        
    }
    
    [self initSlideView];
}


- (void)tabButton:(UIButton *)sender
{
    CGRect frame = _slideView.frame;
    frame.origin.x = sender.frame.origin.x;
    _slideView.frame = frame;
    
    seleType = sender.tag;
    //顶部跟着滑动
    [_topScrollView scrollRectToVisible:CGRectMake(sender.frame.origin.x-sender.frame.size.width*2, 0, _topScrollView.frame.size.width, _topScrollView.frame.size.height) animated:YES];
    paggge = 1;
    
    
    if (seleType == 0) {
        TopPhotos = dicData[@"cicasephoto"];
        [self.mainTableView reloadData];
    }else if (seleType < 3){
        //项目、活动
        [self startSearch];
    }else {
        switch (seleType) {
            case 3://政策
            {
                TopPhotos = dicData[@"policyphoto"];
            }
                break;
            case 4://产业规划
            {
                TopPhotos = dicData[@"industryplanningphooto"];
            }
                break;
            case 5://区域
            {
                TopPhotos = dicData[@"areaphoto"];
            }
                break;
        }
        [self.mainTableView reloadData];
    }
    
    
}

#pragma mark -- 初始化滑动的指示View
-(void) initSlideView {
    
    CGFloat width = 80;
    
    _slideView = [[UIView alloc] initWithFrame:CGRectMake(0, 47, width, 3)];
    [_slideView setBackgroundColor:[UIColor colorWithRed:32/255.f green:165/255.f blue:240/255.f alpha:1.f]];
    [_topScrollView addSubview:_slideView];
}


#pragma mark - 获取数据 项目、
- (void)startSearch
{
    [self showRoundProgressWithTitle:@"请稍后..."];
    //token=验证用户&page=页码&userId=用户id
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    [muDicParameters setObject:self.strUserId forKey:@"userId"];
//    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
    [muDicParameters setObject:[NSString stringWithFormat:@"%ld",paggge] forKey:@"page"];
    
    NSString *strURl = @"";
    
    switch (seleType) {
        case 1://项目
        {
            strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"getMyoutProject_app_myHome.im"];
        }
            break;
        case 2://活动
        {
            strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"getMyoutActivity_app_myHome.im"];
            
        }
            break;
    }
    
    
    
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        [_mainTableView.mj_header endRefreshing];
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//        NSLog(@"%@",dicInfo);

        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            [_mainTableView.mj_header endRefreshing];
            if (paggge == 1) {
                muAryData = [NSMutableArray arrayWithArray:[dicInfo objectForKey:@"data"][@"record"]];
                
                if (muAryData.count == 10) {
                    _mainTableView.mj_footer.hidden = NO;
                }else {
                    _mainTableView.mj_footer.hidden = YES;
                }
                
            }else {
                NSArray *ary11 = [dicInfo objectForKey:@"data"][@"record"];
                for (int i = 0; i<ary11.count; i++) {
                    NSDictionary *dic1 = ary11[i];
                    [muAryData addObject:dic1];
                }
                if (ary11.count == 10) {
                    _mainTableView.mj_footer.hidden = NO;
                }else {
                    _mainTableView.mj_footer.hidden = YES;
                }
                
            }
            
            [self hideBubble];
            [_mainTableView reloadData];

        }else {
            if (paggge == 1) {
                muAryData = [NSMutableArray array];
            }
            
            [_mainTableView reloadData];
            [_mainTableView.mj_header endRefreshing];
            [_mainTableView.mj_footer endRefreshing];

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];

        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [_mainTableView.mj_header endRefreshing];
        [_mainTableView.mj_footer endRefreshing];
        if (paggge == 1) {
            muAryData = [NSMutableArray array];
            [_mainTableView reloadData];
        }


    }];
}

#pragma mark - 关注、取消
- (void)btnClickLove
{
    if ([USER_DEFAULTS objectForKey:@"userid"]!=nil) {

        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
        //token=rE3F2m8AvfC7CVh85O9q&userId=登陆用户id&targetUuserIid=被关注用户的id
        
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
        [muDicParameters setObject:self.strUserId forKey:@"targetUuserIid"];//被关注用户的id
        NSString *strURl = @"";
        if ([dicData[@"isFocus"] isEqualToString:@"否"]) {
            strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusUser_app_myHome.im.lensum"];
        }else {
            strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"focusUser_cannel_app_myHome.im.lensum"];
        }
        
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:strURl parameters:muDicParameters progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
//            NSLog(@"%@",dicInfo);

            if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
                NSInteger focus = [dicData[@"focusNumber"] integerValue];
                if ([dicData[@"isFocus"] isEqualToString:@"否"]) {
                    focus += 1;
                    [btnLove setImage:[UIImage imageNamed:@"project_detail_taoxin_pressed"] forState:UIControlStateNormal];
                    [dicData setObject:@"是" forKey:@"isFocus"];
                }else {
                    focus -= 1;
                    [btnLove setImage:[UIImage imageNamed:@"project_detail_taoxin_normal"] forState:UIControlStateNormal];
                    [dicData setObject:@"否" forKey:@"isFocus"];
                }
                [dicData setObject:[NSString stringWithFormat:@"%ld",focus] forKey:@"focusNumber"];
                
                [btnLove setTitle:[NSString stringWithFormat:@"%ld",focus] forState:UIControlStateNormal];

                [self showRightWithTitle:[dicInfo objectForKey:@"msg"] autoCloseTime:2];
            }else {

               [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

            [self showSingleIconBubble:error.localizedDescription];

        }];
    }else {
        //登录
        UIStoryboard *LoginAndRegister = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginNAV = [LoginAndRegister instantiateViewControllerWithIdentifier:@"LoginNav"];
        [self presentViewController:loginNAV animated:YES completion:nil];
    }
}


- (IBAction)btnClickCallPhone:(id)sender
{
    NSString *strPhone = [NSString stringWithFormat:@"tel://%@",dicData[@"phone"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:strPhone]];
}

#pragma mark - 聊天
- (IBAction)btnClickPostMessage:(id)sender
{

    [self showSingleIconBubble:@"暂未开放此功能"];

}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
